package com.hzp.lolnews.ui.news.view;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseRecyclerViewHolder;
import com.hzp.lolnews.bean.HomeContent;
import com.hzp.lolnews.ui.novel.view.DetailShopActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/10/20 0020.
 */
public class HomeAdapter extends RecyclerView.Adapter<BaseRecyclerViewHolder> {

    private List<HomeContent> mList;
    private Context mContext;
    public void setData(List<HomeContent> list, Context context) {
        this.mList = list;
        this.mContext = context;
        notifyDataSetChanged();
    }

    public void setMoreData(List<HomeContent> list){
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_ltem_commen, parent, false);
        return new BaseRecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder holder, int position) {
        final HomeContent homeContent = mList.get(position);
        SimpleDraweeView simpleDraweeView = holder.getView(R.id.commen_simpleDraweeView);
        simpleDraweeView.setImageURI(homeContent.getArticle_pic());
        TextView tvPin = holder.getView(R.id.commen_tvPin);
        tvPin.setText(homeContent.getArticle_comment());
        TextView tvSource = holder.getView(R.id.commen_tvSource);
        tvSource.setText(homeContent.getArticle_mall());
        TextView tvTime = holder.getView(R.id.commen_tvTime);
        tvTime.setText(homeContent.getArticle_format_date());
        TextView tvTitle = holder.getView(R.id.commen_tvTitle);
        tvTitle.setText(homeContent.getArticle_title());
        TextView tvPrice = holder.getView(R.id.commmen_tvPrice);
        tvPrice.setText(homeContent.getArticle_price());
        TextView tvZhi = holder.getView(R.id.commen_tvZhi);
        tvZhi.setText(homeContent.getArticle_worthy());
        TextView commen_chnnel_name = holder.getView(R.id.commen_chnnel_name);
        commen_chnnel_name.setText(homeContent.getArticle_channel_name());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, DetailShopActivity.class);
                intent.putExtra("getArticle_pic",homeContent.getArticle_pic());
                intent.putExtra("getArticle_type_name",homeContent.getArticle_type_name());
                intent.putExtra("getArticle_format_date",homeContent.getArticle_format_date());
                intent.putExtra("getArticle_title",homeContent.getArticle_title());
                intent.putExtra("getArticle_price",homeContent.getArticle_price());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }


}
